package main

import (
	"context"
	"fmt"
	clientv3 "go.etcd.io/etcd/client/v3"
	"time"
)

func main() {
	defer CLI.Close()

	timeout := 3 * time.Second

	{
		ctx, _ := context.WithTimeout(context.Background(), timeout)
		//resp, err := CLI.Get(ctx, "a", clientv3.WithFromKey()) //从指定的key开始，按字典顺序到结尾
		//resp, err := CLI.Get(ctx, "sample_key", clientv3.WithCountOnly()) //只返回个数  resp.Count
		//resp, err := CLI.Get(ctx, "sample_key", clientv3.WithFirstKey()...) //返回请求范围内的第一个key，貌似得和range配合？ 好像前缀匹配
		//resp, err := CLI.Get(ctx, "sample_key", clientv3.WithFirstRev()...) //获取最老的修改版本
		//resp, err := CLI.Get(ctx, "sample_key", clientv3.WithFirstCreate()...) //获取最早的创建版本
		//CLI.Get(ctx, "sample_key", clientv3.WithFragment())
		//resp, err := CLI.Get(ctx, "sample_key", clientv3.WithKeysOnly()) //只返回key
		//resp, err := CLI.Get(ctx, "sample_key", clientv3.WithLastKey()...) //返回最后一个key，貌似得和range配合？ 奇怪，返回了多个，好像是前缀匹配
		//resp, err := CLI.Get(ctx, "sample_key", clientv3.WithLimit(2))//没懂
		//resp, err := CLI.Get(ctx, "sample_key", clientv3.WithRange("sample_key300")) //[开始,结束)范围内的都返回，务必注意是字符串比较
		//resp, err := CLI.Get(ctx, "sample_key", clientv3.WithRev(11)) //获取指定版本时的值
		resp, err := CLI.Get(ctx, "sample_key", clientv3.WithPrefix()) //前缀匹配
		//resp, err := CLI.Get(ctx, "sample_key", clientv3.WithFilterDelete()) //忽略掉Delete事件
		//resp, err := CLI.Get(ctx, "sample_key", clientv3.WithSort())
		if err != nil {
			panic(err)
		} else {
			fmt.Println("resp:", resp)
			fmt.Println("Count:", resp.Count) //如果获取
			for _, ev := range resp.Kvs {
				fmt.Println("resp:", string(ev.Key), ":", string(ev.Value))
			}
		}
	}
}
